package com.richman.ps38;

import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.richman.controller.NegativeRatioClient;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.Event;

public class PS38Manager {

	
	
	PS38Http account = null;

	public void init() {
		
		Vector<String[]> tmps = NegativeRatioClient.mainWnd.getPS38Accounts();
		
		
		if(tmps.size() > 0) {
			
			PS38Http ps38http = new PS38Http();
			ps38http.setLoginParams(tmps.elementAt(0)[0], tmps.elementAt(0)[1],
					tmps.elementAt(0)[2]);
			
			ps38http.init();
			
			account = ps38http;
			
		}
		

	}
	
	
	
	//-1 最初状态  ,  0 prepareLogin成功, 1 get main page success, 2 登录成功, -2 登录失败,  3抓取成功, -3抓取失败
	public void prepareLogin() {
		

		if(account != null) {
			
			if((account.getStatusCode() == -1 || account.getStatusCode() == -2) && (System.currentTimeMillis() > account.getCanLoginTime()) ) {
				account.prepareLogin();
			}
			
			
		}
		
		
	}
	
	public void getMainPage() {

		if(account != null) {
			
			if(account.getStatusCode() == 0 && (System.currentTimeMillis() > account.getCanGetMainPageTime()) ) {
				account.prepareLogin();
			}
			
			
		}

	}
	
	
	public void login() {
		
		if(account != null) {
			
			if(account.getStatusCode() == 1) {
				account.Login();
			}
			
			
		}

	}



	public int getStatuscode() {
		if(account != null) {
			return account.getStatusCode();
			
		}
		return 0;
	}
	
	
	public void updateStatuscode(int i) {
		if(account != null) {
			account.updateStatusCode(i);
			
		}
	}
	
	
	public Map<String, String> updatePS38Ratio(String betid, String eventid, String bettype, String typedetail, String pankou) {
		
		try {
			
			if(account != null) {
				return account.updatePS38Ratio(betid, eventid, bettype, typedetail, pankou);
				
			}
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		return null;
		
	}



	public void getbalance() {
		if(account != null && account.getStatusCode() == 2 && System.currentTimeMillis() > account.getCanGetBalanceTime() && NegativeRatioClient.isInbet == false) {
			account.getBalance();
			
		}
		
	}

	
	public void getgameresult() {
		if(account != null && account.getStatusCode() == 2 && System.currentTimeMillis() > account.getCanGetResultTime() && NegativeRatioClient.isInbet == false) {
			account.getGameResult();
			
		}
		
	}


	public Map<String ,String> dobet(Map<String, String> oddUpdres, int gold) {
		if(account != null) {
			return account.dobet(oddUpdres, gold);
		}
		return null;
	}



	public void updateps38BetLogData(Vector<BetAdyData> betLogDatas) {
		if(account != null && account.getStatusCode() == 2) {
			account.updateps38BetLogData(betLogDatas);
		}
	} 
	
	public String getMybetsUrl() {
		
		if(account != null) {
			return account.getMybetsUrl();
		}
		
		return null;
	}
	
	
	public String getAccUrl() {
		
		if(account != null) {
			return account.getAccUrl();
		}
		
		return null;
	}
	
	
	public void setCookie() {
		
		if(account != null) {
			account.setCookie();
		}
		
		
	}



	public Map<String, String> manualRebetUpdatePS38Ratio(String betid, String eventid, String bettype,
			String typedetail, String pankou) {
		try {
			
			if(account != null) {
				return account.manualRebetUpdatePS38Ratio(betid, eventid, bettype, typedetail, pankou);
				
			}
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}



	public Event grabOneEvent(String eventidarg, String pankou, String typedetail) {
		if(account != null) {
			return account.grabOneEvent(eventidarg, pankou, typedetail);
			
		}
		
		return null;
	}



	public Map<String, String> manualdobet(Map<String, String> oddUpdres, int gold) {
		if(account != null) {
			return account.manualDobet(oddUpdres, gold);
			
		}
		
		return null;
	}
	
	public String getOutlineData(String count) {
		if(account != null) {
			return account.getOutlineData(count);
		}
		return null;
	}
	
	public String getDetailsData(String datetime) {
		if(account != null) {
			return account.getDetailsData(datetime);
		}
		return null;
	}

	
}
